package com.itgacl.magic4j.modules.mp.config;

import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *  微信公众号相关配置
 *
 */
@Configuration
public class WxServiceConfig {

    @Autowired
    private WxMpConfig wxMpConfig;

    @Bean
    public WxMpService wxMpService() {
        WxMpService wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(this.wxMpConfigStorage());
        return wxMpService;
    }

    @Bean
    public WxMpConfigStorage wxMpConfigStorage() {
        WxMpDefaultConfigImpl wxMpDefaultConfig = new WxMpDefaultConfigImpl();
        wxMpDefaultConfig.setAppId(wxMpConfig.getAppId());
        wxMpDefaultConfig.setSecret(wxMpConfig.getAppSecret());
        wxMpDefaultConfig.setToken(wxMpConfig.getToken());
        return  wxMpDefaultConfig;
    }

}
